//
//  DCReceiveOrderFooter.m
//  JiuyaoDriver
//
//  Created by 大橙子 on 2018/11/26.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCReceiveOrderFooter.h"
@interface DCReceiveOrderFooter ()
@property (nonatomic,strong) UIView *bgView;
@property (nonatomic,strong) DCImageAndTextLabel *nameLabel;
@property (nonatomic,strong) UIImageView *plateImage;
@property (nonatomic,strong) UILabel *plateLabel;
@property (nonatomic,strong) UIView *line;
@property (nonatomic,strong) UIButton *phoneBtn;
@property (nonatomic,strong) UIButton *cuidanBtn;
@property (nonatomic,strong) UIButton *tapBtn;
@end
@implementation DCReceiveOrderFooter
-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpBaseUI];
    }
    return self;
}
-(void)setUpBaseUI
{
    self.bgView = [[UIView alloc]init];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.bgView];
    
    self.nameLabel = [[DCImageAndTextLabel alloc]init];
    self.nameLabel.imageView.image = IMAGENAME(@"name");
    self.nameLabel.textLabel.font = FONT(13);
    [self.bgView addSubview:self.nameLabel];
    
    self.plateImage = [[UIImageView alloc]initWithImage:IMAGENAME(@"车牌")];
    [self.bgView addSubview:self.plateImage];
    
    self.plateLabel = [[UILabel alloc]init];
    self.plateLabel.font = FONT(13);
    [self.bgView addSubview:self.plateLabel];
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = BackgroundColor;
    [self.bgView addSubview:self.line];
    
    UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [tapBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [tapBtn setTitleColor:BlueColor forState:UIControlStateNormal];
    [tapBtn setTitle:@"取消指令" forState:UIControlStateNormal];
    tapBtn.titleLabel.font = FONT(15);
    tapBtn.layer.cornerRadius = 15;
    tapBtn.clipsToBounds = YES;
    tapBtn.layer.borderColor = BlueColor.CGColor;
    tapBtn.layer.borderWidth = 1;
    tapBtn.tag = 2;
    self.tapBtn = tapBtn;
    [self.bgView addSubview:tapBtn];
    
    UIButton *cuidanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cuidanBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [cuidanBtn setTitleColor:BlueColor forState:UIControlStateNormal];
    [cuidanBtn setTitle:@"催单" forState:UIControlStateNormal];
    cuidanBtn.titleLabel.font = FONT(15);
    cuidanBtn.layer.cornerRadius = 15;
    cuidanBtn.clipsToBounds = YES;
    cuidanBtn.layer.borderColor = BlueColor.CGColor;
    cuidanBtn.layer.borderWidth = 1;
    cuidanBtn.tag = 1;
    self.cuidanBtn = cuidanBtn;
    [self.bgView addSubview:cuidanBtn];
    
    UIButton *phoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [phoneBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [phoneBtn setImage:IMAGENAME(@"电话") forState:UIControlStateNormal];
    phoneBtn.tag = 0;
    self.phoneBtn = phoneBtn;
    [self.bgView addSubview:phoneBtn];
}
-(void)layoutSubviews {
    [super layoutSubviews];
    self.bgView.frame = CGRectMake(0, 0, self.width, self.height-1);
    self.nameLabel.frame = CGRectMake(30, 0, 80*WIDTHSCALE6, 30);
    self.plateImage.frame = CGRectMake(self.nameLabel.right+20, 6, 30, 18);
    self.plateLabel.frame = CGRectMake(self.plateImage.right+5, 0, 100*WIDTHSCALE6, 30);
    self.line.frame = CGRectMake(0, self.nameLabel.bottom, self.bgView.width, 1.0);
    __weak typeof(self) weakself = self;
    [self.tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.line.mas_bottom).offset(5);
        make.right.equalTo(weakself.bgView.mas_right).offset(-10);
        make.height.mas_offset(30);
        make.width.mas_offset(80*WIDTHSCALE6);
    }];
    
    [self.cuidanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.line.mas_bottom).offset(5);
        make.right.equalTo(weakself.tapBtn.mas_left).offset(-10);
        make.height.mas_offset(30);
        make.width.mas_offset(80*WIDTHSCALE6);
    }];
    
    [self.phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakself.line.mas_bottom).offset(5);
        make.right.equalTo(weakself.cuidanBtn.mas_left).offset(-10);
        make.height.mas_offset(30);
        make.width.mas_offset(30);
    }];

}
-(void)setModel:(DCOrderReceiveModel *)model {
    _model = model;
    self.nameLabel.textLabel.text = model.driverName;
    self.plateLabel.text = model.plateNumber;
}
-(void)btnDidClick:(UIButton *)button
{
    if (button.tag == 0) {
        DCLog(@"打电话");
        [DCTool call:self.model.driverTel];
    }else if (button.tag == 1){
        if (_delegate && [_delegate respondsToSelector:@selector(selectedWithCuidanBtn:button:)]) {
            [_delegate selectedWithCuidanBtn:@"催单" button:button];
        }
    }else if (button.tag == 2){
        if (_delegate && [_delegate respondsToSelector:@selector(selectedWithCancleOrderBtn:)]) {
            [_delegate selectedWithCancleOrderBtn:@"取消指令"];
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
